/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ro.unibuc.nautilus.dao;

import java.io.Serializable;
import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author Root
 */
public class GenericDAOSpringImpl<T, PK extends Serializable>
        extends HibernateDaoSupport implements GenericDAO<T, PK> {

    private Class<T> type;

    public GenericDAOSpringImpl(Class<T> type) {
        this.type = type;
    }

    public PK create(T o) {
        return (PK) getHibernateTemplate().save(o);
    }

    public T find(PK id) {
        return (T) getHibernateTemplate().get(type, id);
    }

    public void update(T o) {
        getHibernateTemplate().update(o);
    }

    public void delete(T o) {
        getHibernateTemplate().delete(o);
    }

    public List<T> findAll() {
        return getHibernateTemplate().loadAll(type);
    }
}
